import pymysql
from sqlalchemy import create_engine

class PyMysql(object):
    def __init__(self):
        self.host='localhost'
        self.user='root'
        self.passwd ='root'
        self.db = 'test'
        self.port = 3306
        self.charset = 'utf8'

    def  pymysql_conn(self):
        conn=pymysql.connect(
            host=self.host,
            user=self.user,
            passwd=self.passwd,
            db=self.db,
            charset=self.charset
        )
        cur=conn.cursor()
        return cur


    def sqlalchemy_conn(self):
        user=self.user
        password=self.passwd
        host=self.host
        db=self.db
        charset=self.charset

        print(user)
        print('密码',password)

        engine=create_engine("mysql+pymysql://{}:{}@{}/{}?charset={}".format(user,password,host,db,charset))
        #engine=create_engine("mysql+pymysql://root:root@localhost:3306/test?charset=utf8")
        con=engine.connect()

        return con





